package pl.edu.pw.elka.tinyrepo.gate.server;

import java.rmi.RemoteException;
import java.rmi.server.RemoteServer;
import java.rmi.server.ServerNotActiveException;

import pl.edu.pw.elka.tinyrepo.dataserver.server.DataServerFacade;

/**
 * @author Piotr Jarosik
 */
public class GateFacadeImpl implements GateFacade {
   /** */
   private static final long serialVersionUID = -9149547602348410544L;
   /** Uruchomiony serwer danych. */
   private GateServer server;
   
   public GateFacadeImpl(GateServer server) {
      this.server = server;
   }
   
   public void register(DataServerFacade ds, Integer port) throws RemoteException {
      try {
         server.addDataServer(RemoteServer.getClientHost()+":"+port, ds);
      } catch (ServerNotActiveException e) {
         e.printStackTrace();
      }
   }

   @Override
   public boolean putFile(String path, Integer id, Long size, Integer port) throws RemoteException {
      try {
         return server.putFile(path, id, size, RemoteServer.getClientHost()+":"+port);
      } catch (ServerNotActiveException e) {
         e.printStackTrace();
         return false;
      }
   }

   @Override
   public boolean dropFile(String path) throws RemoteException {
      return server.removeFile(path); // tylko usuniecie wpisu.
   }
   
}
